﻿var lsInfo = {
  current: 1,
  pageSize: allPageSize,
  data: [],
  totalRow: 0,
  totalPage: 0,
  oneDate: {},
  editState: false
};

// document.getElementById('nav').innerHTML = template('navs', navinfo2);

$('#nav li').eq(3).addClass('active');

var getList = function (obj) {
  $.ajax({
    cache: false,
    async: false,
    url: '/api/CommonApi?API=GetTeacherMonthApplysByRole',
    type: 'get',
    data: {
      ProjectName: searchObj.ProjectName,
      StartDate: searchObj.StartDate,
      EndDate: searchObj.EndDate,
      sorts: ' StartDate DESC',
      pagesize: obj.size,
      page: obj.index
    },
    dataType: 'json',
    success: function (data) {
      // console.log(data)
      if (data.Success) {
        obj.callback(data)
      }
    }
  });
};

getList({
  size: lsInfo.pageSize,
  index: lsInfo.current,
  callback: function (data) {
    // console.log(data)
    // console.log(JSON.stringify(data));
    var newData = data.ApiParamObj[0];
    for (var key in newData) {
      if (newData[key]['State'] === '????') {
        newData[key]['State'] = '';
      }
    }
    // 列表数据
    document.getElementById('listTable').innerHTML = template('l43List', newData);
    // 分页
    var pagesInfo = data.ApiParamObj[1];
    lsInfo.data = newData;
    lsInfo.totalRow = pagesInfo[0].totalRow;
    lsInfo.totalPage = pagesInfo[0].totalPage;

    $('#totalRow').html(lsInfo.totalRow);
    pagesSet(lsInfo);
    setPageSize(lsInfo);
    loading.hide();
  }
});

// 点击分页请求事件
var showPage = function (o) {
  // console.log(o)
  getList({
    size: o.pageSize,
    index: o.current,
    callback: function (data) {
      // console.log(data)
      // console.log(JSON.stringify(data));
      var newData = data.ApiParamObj[0];
      for (var key in newData) {
        if (newData[key]['State'] === '????') {
          newData[key]['State'] = '';
        }
      }
      // 列表数据
      document.getElementById('listTable').innerHTML = template('l43List', newData);
      // 分页
      var pagesInfo = data.ApiParamObj[1];
      o.data = newData;
      o.totalRow = pagesInfo[0].totalRow;
      o.totalPage = pagesInfo[0].totalPage;

      $('#totalRow').html(o.totalRow);
      pagesSet(o);
      loading.hide();
    }
  });
};

// 预览报销单
$('#table').on('click', '.view', function () {
  var index = $(this).parent().parent().index();
  lsInfo.oneDate = lsInfo.data[index];
  var v = lsInfo.oneDate;
  var date = new Date(v.StartDate).pattern('yyyy-MM-dd#HH-mm-ss');
  // console.log(v)
  // window.location.href = '/Finance/Project/print/' + v.MonthApplyID + '=' + date;
  // window.open('/PM/Project/print2/' + v.MonthApplyID + '=' + date + '=' + v.State, '_blank');
  var url = '/PM/Project/print2/' + v.MonthApplyID + '=' + date + '=' + v.State;
  window.location.href = url;
  // $('#editCost').modal('show');
  return false;
});